-
Notifications
You must be signed in to change notification settings - Fork 20
ENT-5725: Added vagrant provider for spawning VMs #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a great start! I have added some notes on things we have solved in jenkins-vms regarding various bits.
node.vm.provider "virtualbox" do |vb| | ||
vb.memory = VM_MEMORY | ||
vb.cpus = VM_CPUS | ||
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding time and dns you might need to include this snippet from jenkins-vms that handles darwin/macos
cf_remote/Vagrantfile
Outdated
# previously working Vagrantfiles: | ||
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact | ||
v.qemu_use_session = false | ||
override.vm.synced_folder "./", "/vagrant", type: :rsync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
synced folders are also tricky for older distributions like debian-9:
here are some workarounds for centos-7 and old debians:
429b367
to
8ff3c80
Compare
8ff3c80
to
c96596d
Compare
c96596d
to
be78500
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 🚀 Some smaller comments
While reviewing your PR, I never understood what the config
argument to ssh
and scp
is for, or why it's necessary. Could you explain?
When you spawn a vagrant VM, vagrant generates a ssh config file with a private key and everything set up correctly. You can inspect it by running The variable "config" is simply the path to the vagrant-ssh-config file inside the VM's directory. If it is not None, then the connection will connect using it. |
be78500
to
73e9bd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are some failing test :)
73e9bd8
to
fa2fa4f
Compare
I was thinking we could improve the Vagrantfile and other mechanics, like default provisioning scripts, in future iterations |
default="aws", | ||
choices=["aws", "gcp", "vagrant"], | ||
) | ||
sp.add_argument("--cpus", help="Number of CPUs of the vagrant instances", type=int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider having a default 1 CPUs
sp.add_argument("--cpus", help="Number of CPUs of the vagrant instances", type=int) | |
sp.add_argument("--cpus", default=1, help="Number of CPUs of the vagrant instances", type=int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't have a default cpu because I check if "cpus" is defined when validating args, because I don't allow to define the number of cpus for AWS spawned machines
6af64fc
to
1f44cbe
Compare
Ticket: ENT-5725 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1f44cbe
to
3887067
Compare
vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ] | ||
vb.customize [ "modifyvm", :id, "--uartmode1", "file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are these doing in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is to fix the bug mentioned in the ticket in the comment above (ubuntu/focal64 very slow to boot and reboots once ) . I got that from the Vagrantfile in starter_pack
memory = 1024 | ||
if sync_folder is None: | ||
sync_folder = os.getenv("CF_REMOTE_SYNC_ROOT", "/tmp") | ||
if sync_folder == "/tmp": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the VagrantVM.info()
function above it looks like the default sync directory is /northern.tech
. While here it seems to be /tmp
.
I wonder if syncing the /tmp
folder can have some security issues. E.g., maybe systemd
on both the host machine and the VM starts writing to the same files? Not sure. A good default would be no sync folder at all. You don't really need it if you are using cf-remote to install CFEngine and to deploy policy.
sync_folder = os.getenv("CF_REMOTE_SYNC_ROOT", "/tmp") | ||
if sync_folder == "/tmp": | ||
log.warning( | ||
"The synched folder has not been specified. The default synched folder will be set to '/tmp'. \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/folder/directory/g
return [ | ||
VagrantVM( | ||
"{}-{}".format(name, i + 1), | ||
"{}.{}".format(start, end % 255), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to fix the potential conflicting IP address issue?
configs = read_json(SSH_CONFIGS_JSON_FPATH) | ||
|
||
with open(SSH_CONFIG_FPATH, "w") as f: | ||
if configs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should do this if before opening the file?
It was a bit hard to know exactly what approach to take so if you have any better ideas I am interested
This doesn't exactly work yet, because
I am not sure how we should provision the created vms. We could:
nt-discovery.sh
and find all the information we need (like what package manager it uses, etc...) then provision it with a modular script using the collected data.